package com.ruoyi.bk.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bk.domain.LayoutConfig;
import com.ruoyi.bk.service.ILayoutConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 页面拖拽Controller
 *
 * @author ruoyi
 * @date 2025-05-12
 */
@RestController
@RequestMapping("/bk/LayoutConfig")
public class LayoutConfigController extends BaseController
{
    @Autowired
    private ILayoutConfigService layoutConfigService;

    /**
     * 查询页面拖拽列表
     */
//    @PreAuthorize("@ss.hasPermi('bk:LayoutConfig:list')")
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(LayoutConfig layoutConfig)

    {
        startPage();
        List<LayoutConfig> list = layoutConfigService.selectLayoutConfigList(layoutConfig);
        return getDataTable(list);
    }

    /**
     * 导出页面拖拽列表
     */
    @PreAuthorize("@ss.hasPermi('bk:LayoutConfig:export')")
    @Log(title = "页面拖拽", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LayoutConfig layoutConfig)
    {
        List<LayoutConfig> list = layoutConfigService.selectLayoutConfigList(layoutConfig);
        ExcelUtil<LayoutConfig> util = new ExcelUtil<LayoutConfig>(LayoutConfig.class);
        util.exportExcel(response, list, "页面拖拽数据");
    }

    /**
     * 获取页面拖拽详细信息
     */
    @PreAuthorize("@ss.hasPermi('bk:LayoutConfig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(layoutConfigService.selectLayoutConfigById(id));
    }

    /**
     * 新增页面拖拽
     */
    @PreAuthorize("@ss.hasPermi('bk:LayoutConfig:add')")
    @Log(title = "页面拖拽", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LayoutConfig layoutConfig)
    {
        return toAjax(layoutConfigService.insertLayoutConfig(layoutConfig));
    }

    /**
     * 批量修改页面拖拽配置
     */
    @PreAuthorize("@ss.hasPermi('bk:LayoutConfig:edit')")
    @Log(title = "页面拖拽", businessType = BusinessType.UPDATE)
    @PutMapping("/batch")
    public AjaxResult batchUpdate(@RequestBody List<LayoutConfig> layoutConfigs)
    {
        return toAjax(layoutConfigService.batchUpdateLayoutConfig(layoutConfigs));
    }

    /**
     * 修改页面拖拽
     */
    @PreAuthorize("@ss.hasPermi('bk:LayoutConfig:edit')")
    @Log(title = "页面拖拽", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LayoutConfig layoutConfig)
    {
        return toAjax(layoutConfigService.updateLayoutConfig(layoutConfig));
    }

    /**
     * 删除页面拖拽
     */
    @PreAuthorize("@ss.hasPermi('bk:LayoutConfig:remove')")
    @Log(title = "页面拖拽", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(layoutConfigService.deleteLayoutConfigByIds(ids));
    }
}